package com.stable.model;

import com.stable.spider.ths.XLSData;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.util.Arrays;
import java.util.List;

public class WorkBookCommon {


    public static HSSFWorkbook workBook(String code) {
        //
        HSSFWorkbook workbook = new HSSFWorkbook();//创建Excel文件(Workbook)

        //利润表
        String benefitUrlStr = "http://basic.10jqka.com.cn/api/stock/export.php?export=benefit&type=year&code=" + code;
        List benefitRowTitle = Arrays.asList("科目\\时间",
                "财务费用(元)",
                "三、营业利润(元)",
                "减：所得税费用(元)"
        );
        List<XLSData> benefitList = HSSFUtil.xlsParse(benefitRowTitle, benefitUrlStr);
        System.out.println(benefitList);

        //现金流量表
        String cashUrlStr = "http://basic.10jqka.com.cn/api/stock/export.php?export=cash&type=year&code=" + code;
        List cashRowTitle = Arrays.asList("科目\\时间",
                "净利润(元)",
                "固定资产折旧、油气资产折耗、生产性生物资产折旧(元)",
                "购建固定资产、无形资产和其他长期资产支付的现金(元)",
                "加：资产减值准备(元)",
                "无形资产摊销(元)",
                "长期待摊费用摊销(元)",
                "处置固定资产、无形资产和其他长期资产的损失(元)",
                "固定资产报废损失(元)",
                "经营活动产生的现金流量净额(元)");
        List<XLSData> cashList = HSSFUtil.xlsParse(cashRowTitle, cashUrlStr);
        System.out.println(cashList);

        //资产负债表
        String debtUrlStr = "http://basic.10jqka.com.cn/api/stock/export.php?export=debt&type=year&code=" + code;
        List debtRowTitle = Arrays.asList("科目\\时间",
                "长期股权投资(元)",
                "固定资产合计(元)",
                "无形资产(元)",
                "长期待摊费用(元)",
                "递延所得税资产(元)",
                "流动资产合计(元)",
                "货币资金(元)",
                "流动负债合计(元)",
                "一年内到期的非流动负债(元)");
        List<XLSData> debtList = HSSFUtil.xlsParse(debtRowTitle, debtUrlStr);
        System.out.println(debtList);

        //主要指标表
        String mainUrlStr = "http://basic.10jqka.com.cn/api/stock/export.php?export=main&type=year&code=" + code;
        List mainRowTitle = Arrays.asList("科目\\时间",
                "净资产收益率",
                "净利润同比增长率",
                "扣非净利润同比增长率",
                "净利润(元)");
        List<XLSData> mainList = HSSFUtil.xlsParse(mainRowTitle, mainUrlStr);
        System.out.println(mainList);

        //PEPB一键估值
        PE3PB3.PE3PB3writeXls(code, workbook, benefitList, cashList, debtList, mainList);

        //PB三阶段估值模型变身
        //PB3change.PB3changeWriteXls(code, workbook, benefitList, cashList, debtList, mainList);

        //PE三阶段估值模型变身
        //PE3change.PE3changeWriteXls(code, workbook, benefitList, cashList, debtList, mainList);

        //股东价值-PE三阶段估值模型
        PE3.PE3writeXls(code, workbook, benefitList, cashList, debtList, mainList);

        //自由现金流折现模型
        VAFCFF.VAFCFFwriteXls(code, workbook, benefitList, cashList, debtList);
        //维持性资本支出
        WCXZBZC.WCXZBZCwriteXls(code, workbook, benefitList, cashList, debtList);
        //计算FCFF
        FCFF.FCFFwriteXls(code, workbook, benefitList, cashList, debtList);
        return workbook;
    }
}
